package com.ctshk.rpc.goods.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ctshk.rpc.goods.dto.CommoditySpecificationsNameDTO;
import com.ctshk.rpc.goods.dto.CommoditySpecificationsPageDTO;
import com.ctshk.rpc.goods.entity.CommoditySpecificationsName;
import com.ctshk.rpc.goods.mapper.provider.CommoditySpecificationsNameProvider;
import com.ctshk.rpc.goods.req.CommoditySpecificationsNamePageReq;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;

import java.util.List;

/**
 * <p>
 * 商品规格名称 Mapper 接口
 * </p>
 *
 * @author 姜斌文
 * @since 2021-04-12
 */
public interface CommoditySpecificationsNameMapper extends BaseMapper<CommoditySpecificationsName> {
	
	@Select("SELECT t.id, t.specifications_name FROM t_commodity_specifications_name t WHERE t.is_deleted = 0")
	List<CommoditySpecificationsNameDTO> findCommoditySpecificationsNameByAll();

	@Select("SELECT t.id, t.specifications_name FROM t_commodity_specifications_name t WHERE t.is_deleted = 0 and id = #{id}")
	List<CommoditySpecificationsNameDTO> findCommoditySpecificationsNameById(@Param("id") Long id);

	@Select("select t.id, t.specifications_name from t_commodity_specifications_name t where t.is_deleted = 0 and t.specifications_name = #{specificationsName}")
	CommoditySpecificationsNameDTO findCommoditySpecificationsNameBySpecificationsName(@Param("specificationsName") String specificationsName);

	
	@SelectProvider(type = CommoditySpecificationsNameProvider.class, method = "findCommoditySpecificationsNameByPageAll")
    IPage<CommoditySpecificationsPageDTO> findCommoditySpecificationsNameByPageAll(IPage<CommoditySpecificationsPageDTO> page,
			CommoditySpecificationsNamePageReq pageReq);
	
	@Select("SELECT  s.id, s.specifications_name_id, s.specifications, GROUP_CONCAT(a.attribute_name) AS \"attribute_name\""
			+ " FROM t_commodity_specifications_attribute a "
			+ "RIGHT JOIN  t_commodity_specifications s ON s.id = a.specifications_id "
			+ "RIGHT JOIN  t_commodity_specifications_name t ON t.id = s.specifications_name_id "
			+ "WHERE s.is_deleted = 0 "
			+ "GROUP BY s.id, s.specifications_name_id, s.specifications")
	List<CommoditySpecificationsPageDTO> findCommoditySpecificationsNameBySonAll();
	
}
